;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Sales.SalesDeleted", [])
        .controller("SalesDeletedListCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService) {
            $scope.markInfo = {
                curRow: -1
            };
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("device", "/saleIntentionDeleteReason/export"),
            };
            $scope.condition = {};
            $scope.dataList = [];
            $scope.toolbarConfig = {
                showColConfig: false
            };
            $scope.tbConf = {
                scrollWidth: 1070,
                tableCol: [
                    {
                        name: "销售单号",
                        dataField: "saleNo",
                        width: 170,
                        isShow: true,
                    },
                    {
                        name: "零件号",
                        dataField: "materialNo",
                        width: 170,
                        isShow: true,
                    },
                    {
                        name: "零件中文名",
                        dataField: "materialName",
                        width: 120,
                        isShow: true,
                    },
                    {
                        name: "数量",
                        dataField: "amount",
                        width: 120,
                        isShow: $scope.isSCH,
                    },
                    {
                        name: "删除人",
                        dataField: "deleteName",
                        width: 120,
                        isShow: true,
                    },
                    {
                        name: "删除时间",
                        dataField: "deleteDateF",
                        width: 140,
                        isShow: true,
                    },
                    {
                        name: "删除原因",
                        dataField: "deleteReason",
                        width: 140,
                        isShow: true,
                    }
                ]
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.toSort = function (config, index) {
                ybWidget.ToSort(config, index);
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.cueRow = index
            };

            // $scope.checkDate = function (obj, startFiled, endFiled) {
            //     var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
            //     if (!!timeFormatObj.tStart) {
            //         obj[startFiled] = timeFormatObj.tStart;
            //     }
            //     if (!!timeFormatObj.tEnd) {
            //         obj[endFiled] = timeFormatObj.tEnd;
            //     }
            // };

            function getDataList(curPage) {
                $scope.markInfo.curRow = -1;
                var service = "device";
                var reqUrl = "/saleIntentionDeleteReason/list";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                param.filters = angular.copy($scope.condition);
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    var df = "yyyy-MM-dd HH:mm:ss";
                    angular.forEach(resp.value.list, function (item) {
                        item.deleteDateF = $filter("YbDate")(item.deleteDate, df);
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            (function () {
                getDataList();
            })();
        }])
    ;
})(window, window.angular);